package top.appx.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.springframework.stereotype.Repository;
import top.appx.dao.UserDao;
import top.appx.entity.UserEntity;
import top.appx.vo.Pager;

import java.util.List;

/**
 * Created by zwy on 2015-5-20.
 */
@Repository
public class UserDaoImpl extends  BaseDaoImpl<UserEntity> implements UserDao {
    public Pager<UserEntity> queryByPage(UserEntity bean, int page, int rows) {
        Criteria c = this.getCurrentSession().createCriteria(UserEntity.class);
        int total = ((Number)c.setProjection(Projections.rowCount()).uniqueResult()).intValue();
        c.setProjection(null);

        c.setFirstResult((page-1)*rows);
        c.setMaxResults(rows);
        List list = c.list();
        Pager<UserEntity> result = new Pager<UserEntity>();
        result.setTotal(total);
        result.setRows(list);

        return result;
    }
}
